﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TREE_VIEW详细使用
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            /*
             方案1 
             */

            /*
            //创建根节点
            TreeNode root = new TreeNode("广东东软学院");
            this.treeView1.Nodes.Add(root);


            //创建子节点
            TreeNode treeNode1 = new TreeNode("计算机系");
            TreeNode treeNode2 = new TreeNode("电子商务系");
            //创建关联
            root.Nodes.Add(treeNode1);
            root.Nodes.Add(treeNode2);

            //创建课程节点
            TreeNode CouseNode1 = new TreeNode("C#程序设计");
            TreeNode CouseNode2 = new TreeNode("WinForm程序设计");
            TreeNode CouseNode3 = new TreeNode("电子商务概论");
            TreeNode CouseNode4 = new TreeNode("网络营销");
            TreeNode CouseNode5 = new TreeNode("网络营销");
            //将课程节点添加到子节点中
            treeNode1.Nodes.Add(CouseNode1);
            treeNode1.Nodes.Add(CouseNode2);
            treeNode2.Nodes.Add(CouseNode3);
            treeNode2.Nodes.Add(CouseNode4);
            treeNode2.Nodes.Add(CouseNode5);
            //删除多余节点
            this.treeView1.Nodes.Remove(CouseNode5);
            //展开所有节点
            this.treeView1.ExpandAll();
            */

            /*方案2*/
            this.treeView1.Nodes.Add("001", "广东东软学院");
            this.treeView1.Nodes["001"].Nodes.Add("00101", "计算机系");
            this.treeView1.Nodes["001"].Nodes.Add("00102", "电子商务系");
            this.treeView1.Nodes["001"].Nodes["00101"].Nodes.Add("0010101", "C#程序设计");
            this.treeView1.Nodes["001"].Nodes["00101"].Nodes.Add("0010102", "WinForm程序设计");
            this.treeView1.Nodes["001"].Nodes["00102"].Nodes.Add("0010201", "电子商务概论");
            this.treeView1.Nodes["001"].Nodes["00102"].Nodes.Add("0010202", "网络营销");
            this.treeView1.ExpandAll();

            //删除节点
            this.treeView1.Nodes[0].Nodes[0].Remove();
            //this.treeView1.Nodes["001"].Nodes["00101"].Remove();
        }
    }
}
